/**
* Copyright (C)2001-2099 Zeai.cn All rights reserved.
* E-Mail：supdes#qq.com　QQ:797311
* http://www.a9a.cn
* http://www.zeai.cn
* http://www.yzlove.com
* Last update 2021/11/11 by supdes 
* 作 者:郭余林 QQ:797311 (supdes)
*/
document.write('<input type="hidden" id="p" value="1" />');
var loadswitch,WTFarr = [];	
window.onhashchange = processHashWaterfall;window.onload = processHashWaterfall;
document.body.onscroll = function(){
	var tt = zeai.getScrollTop(),cH= parseInt(document.documentElement.clientHeight),sH= parseInt(document.body.scrollHeight);//cH=document.documentElement.clientHeight;
	sessionStorage.tt=tt;
	if ((sH-tt-cH) <100 && loadswitch){
		var i = parseInt(o("p").value);
		//游弹
		if(i==2 && !iflogin){
			setTimeout(function(){index_divclose=ZeaiM.div({obj:index_bounce_box,w:30,h:30});},100);
			loadswitch=false;
			return false
		}
		//游弹 END
		i++;o("p").value = i;
		location.hash = "#" + i;
		if (i > ZEAI_totalP){
			location.hash = "#" + ZEAI_totalP;
			o("p").value  = ZEAI_totalP;
			return false;
		}else{
			if(i>ZEAI_totalP){end.html('没有更多了');return false;}
			loadswitch=false;
			Object.assign(zeaiOnscroll_json.data,{p:i});
			zeai.ajax(zeaiOnscroll_json,function(e){if (e == 'end'){return false;}else{waterfall_p_load(ZEAI_list,e,i);}});
		}
	}
	backtopFn();
}
window.addEventListener('pageshow', function (event) {
	if(event.persisted || window.performance && window.performance.navigation.type == 2){
		o('ZEAI_list').html(sessionStorage.tmplist_wt);
		if(sessionStorage.WTFarr!='[]' && !zeai.empty(sessionStorage.WTFarr)){
			WTFarr=JSON.parse(sessionStorage.WTFarr);
		}
		zeai.setScrollTop(sessionStorage.tt);
		loadswitch=true;
		ZEAI_list.style.height=getH()+'px';
	}
},false);
/*ppl*/
function pplLoad(ZEAI_list) {
	var adom=zeai.tag(ZEAI_list,'a'),aL=adom.length,s=0,img,s=1;
	zeai.listEach(adom,function(obj,i){
		var img=obj.firstChild.children[0];img.onerror=function(){this.src='res/photo_m'+obj.getAttribute("sex")+'.png';}
		var imgTMP = new Image();imgTMP.src=img.src;
		var tmpdiv=zeai.addtag('div');tmpdiv.hide();tmpdiv.append(imgTMP);
		imgTMP.onload=function(){s++;if (s >= aL){pplInit(ZEAI_list);tmpdiv.remove();}}
	});
}
function pplInit(ZEAI_list){WTFarr = [];p=2,waterfall(ZEAI_list);}
function waterfall(ZEAI_list){
	var columns = 2,ulist=zeai.tag(ZEAI_list,'a');
	zeai.listEach(ulist,function(obj,i){
		var w=obj.offsetWidth,h=obj.offsetHeight,boxheight=h;
		var minobj_L;
		if (i<columns){
			obj.css('transform:translate('+w*i+'px,0px)');
			WTFarr.push(boxheight);
		}else{
			//找到数组最小高和索引
			var minHeight = WTFarr[0],index = 0,WTFarrL=WTFarr.length;
			for (var j = 0; j < WTFarrL; j++) {if (minHeight > WTFarr[j])index = j;}
			//设置下一行的第一个盒子位置top值就是最小列高 
			minobj_L = (index > 0)?w+'px':'0px';
			obj.css('transform:translate('+minobj_L+','+WTFarr[index]+'px)');
			//改最小列高 最小列高 = 当前自己高 + 拼接过来的高
			WTFarr[index] = WTFarr[index] + boxheight;
		}
	});
	ZEAI_list.style.height=getH()+'px';
	if(sessionStorage.WTFarr=='[]' || zeai.empty(sessionStorage.WTFarr)){sessionStorage.WTFarr=JSON.stringify(WTFarr);}
}
function getH(){return Math.max.apply(null,WTFarr);}
function waterfall_p_load(mainobj,e,p){
	var columns = 2;
	var div = zeai.addtag('div');div.id='p'+p;div.append(e);
	var newlist = zeai.tag(div,'a');
	mainobj.append(div);
	var l = newlist.length,m = 0;
	zeai.listEach(newlist,function(obj,i){
		minobj_L = (i % 2 == 0)?'50vw':'0px';
		var WTFtop=Math.max.apply(null,WTFarr)+200;
		obj.css('transform:translate('+minobj_L+','+WTFtop+'px)');
		var img=obj.firstChild.children[0];
		img.onload=function(){m++;if (m >= l)imgInit();}
		img.onerror=function(){this.src='res/photo_m'+obj.getAttribute("sex")+'.png';}
	});
	function imgInit(){
		zeai.listEach(newlist,function(obj){
			var w=obj.offsetWidth,h=obj.offsetHeight,minobj_L,aHeight = h;
			var minHeight = WTFarr[0],index = 0,WTFarrL=WTFarr.length;
			for (var j = 0; j < WTFarrL; j++) {if (minHeight > WTFarr[j]){index = j;}}
			minobj_L = (index > 0)?w+'px':'0px';
			obj.css('transform:translate('+minobj_L+','+WTFarr[index]+'px)');
			WTFarr[index] = WTFarr[index] + aHeight;
		});
		loadswitch=true;
		sessionStorage.tmplist_wt += div.innerHTML;
		sessionStorage.WTFarr=JSON.stringify(WTFarr);
		ZEAI_list.style.height=getH()+'px';
	}
}